<template lang="html">
<div class="login">
    <div class="login-head semibold">
      <a @click="goBack()" class="close"><img src="4_icon_back.png"></a>
      <span>登录</span>
    </div>
    <div class="login-content">
        <div class="input-group">
            <div class="input-warp"><input name="username" v-model="username" type="text" placeholder="邮箱或用户名"></div>
            <div class="input-warp"><input name="password" v-model="password" type="password" placeholder="密码"></div>
        </div>
        <div class="input-group"><a @click="sendLogin()" class="login-buttom">登录</a></div>
        <div class="input-group"><router-link class="login-register" :to="'/main/register'">还没有账号？立即注册</router-link></div>
    </div>
</div>
</template>
<style lang="postcss">
.login{
    position: absolute;
    height: 100%;
    background-color: #fff;
    overflow: hidden;
}
.login-head{
    font-size: 0.25rem;
    text-align: center;
    line-height: 0.35rem;
    padding: 0.5rem 0 0.1rem 0;
}
.login-content{
    background-color: #fff;
    padding: 0.05rem 0 0.45rem;
    height: 100%;
    .input-group{
        color: #A5A5A5;
        padding: 0.1rem 0.2rem;
        .input-warp {
            input{
                font-size: 0.14rem;
                line-height: 0.35rem;
                width: 3.14rem;
                padding: 0.05rem 0.1rem;
                border: 0.01rem solid #E2E4E6;
                overflow: hidden;
                outline: none;
                resize: none;
            }
            input::placeholder{
                color:#C0C0C0;
            }
        }
        .login-buttom{
            color: #fff;
            background-color: #6BC8BB;
            width: 100%;
            font-size: 0.14rem;
            line-height: 0.3rem;
            display: block;
            text-align: center;
            border-radius: 0.04rem;
        }
        .login-register{
            display: block;
            font-size: 0.14rem;
            line-height: 0.2rem;
            text-decoration: underline;
            text-align: center;
            font-weight: 200;
            color: #C0C0C0;
        }
    }
}
</style>
<script>
import store from '../store'
export default {
    name: 'login',
  data: function(){
    return {
      show: true,
      username: '',
      password: '',
    }
  },
  computed: {
    islogin () {
      return store.state.islogin
    }
  },
  components: {
  },
  mounted: function() {
      if(this.islogin == 1){
          this.$router.push('/');
      }
  },
  methods: {
    goBack () {
      window.history.length > 1
        ? this.$router.go(-1)
        : this.$router.push('/')
    },
    sendLogin(){
        if(!this.username || !this.password){
            alert('请填写用户名和密码！');
        }else{
            this.$http.post('/auth/login',{
                username: this.username,
                password: this.password
            })
            .then((response) => {
                if(response.data.code == 1){
                    store.commit('LOGIN');
                    this.$router.push('/')
                }else{
                    alert(response.data.msg);
                }
            })
            .catch((err) => {
                alert(err);
            })
            ;
        }
    }
  }
}
</script>